package app.utils;

import java.io.File;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import app.log.APPLog;

/**
 * @author CUNGUANTONG
 * @date 2011-12-14
 * @version
 * @description 工具处理类
 */
public class Tools {
    
    public static final String YYYY_MM_DD = "yyyy-MM-dd";
    public static final String YYYYMMDD = "yyyyMMdd";
    public static final String YYYYMM = "yyyyMM";
    public static final String YYYY_MM = "yyyy-MM";
    /**
     * 允许执行
     */
    public static final int ALLOW_EXCUTE = 12;
    /**
     * 拒绝因为需要其他数据支持 (判断加挂帐户即获取帐户列表)
     */
    public static final int REFUSE_FOR_NEED_DATA = 13;
    /**
     * 拒绝因为不可预料的原因  非高级网银等
     */
    public static final int REFUSE_FOR_OTHER = 14;
    /**
     * 修改限额
     */
	public static final int ACTION_TO_LIMIT = 100;
	/**
	 * 修改帐户
	 */
	public static final int ACTION_TO_ACCOUNT = 200;
	/**
	 * 激活
	 */
	public static final int ACTION_TO_ACTIVE = 300;
	
    /**
     * 
     * [判断身份证号码是否正确]<BR>
     * [功能详细描述]
     * @param idNum 身份证号码
     * @return
     */
    public static boolean checkUserId(String idNum){
        int idLength = idNum.length();
        if (idLength != 15 && idLength != 18) {
            return false;
        }      
        //验证身份证号码出身月日
        String m = "";
        String d = "";       
        if (idLength == 15) {
            m = idNum.substring(8, 10);
            d = idNum.substring(10, 12);
        }else {
            m = idNum.substring(10, 12);
            d = idNum.substring(12, 14);
        }
        int mInt = Integer.parseInt(m);
        int dInt = Integer.parseInt(d);
        if (mInt>12||dInt>31) {
            return false;
        }      
        //如果是15位身份证号码，不进行下面算法的验证
        if (idLength == 15) {
            return true;
        }
        
        //加权因子 7 9 10 5 8 4 2 1 6 3 7 9 10 5 8 4 2
        int w[] = {7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};
        int sum = 0;
        for (int i = 0; i < 17; i++) {
            String a = idNum.substring(i,i+1);
            int aInt = Integer.parseInt(a);
            sum += aInt * w[i];
        }
        int mod = sum % 11;
        boolean isValid = false;
        String lastC = idNum.substring(17,18);
        //mod: 0 1 2 3 4 5 6 7 8 9 10 
        //校验码: 1 0 X 9 8 7 6 5 4 3 2
        switch (mod) {
            case 0:   
                isValid = (lastC.equals("1")?true:false);
                break;
            case 1:
                isValid = (lastC.equals("0")?true:false);
                break;
            case 2:
                isValid = (lastC.equals("X")?true:false);
                if (!isValid) {
                    isValid = (lastC.equals("x")?true:false);
                }
                break;
            case 3:
                isValid = (lastC.equals("9")?true:false);
                break;
            case 4:
                isValid = (lastC.equals("8")?true:false);
                break;
            case 5:
                isValid = (lastC.equals("7")?true:false);
                break;
            case 6:
                isValid = (lastC.equals("6")?true:false);
                break;
            case 7:
                isValid = (lastC.equals("5")?true:false);
                break;
            case 8:
                isValid = (lastC.equals("4")?true:false);
                break;
            case 9:
                isValid = (lastC.equals("3")?true:false);
                break;
            case 10:
                isValid = (lastC.equals("2")?true:false);
                break;
            default:
                break;
        } 
        return isValid;
    }
	
    /**
     * 
     * [判断一账通用户名是否符合要求]<BR>
     * [功能详细描述]
     * @param name 一账通用户名
     * @return
     */
   public static String checkUserName(String name){
    	
    	int nameLength = name.length();
        // 4-30位
        if(nameLength<4 || nameLength>30){
            return "用户名不能少于4位且不能大于30位，请您重新设置。"; 
        }
        
        // 纯数字用户名不能超过11位
        if(Tools.isNumeric(name) && nameLength > 11){
        	return "纯数字用户名不能超过11位。"; 
        }
        
        // 用户名不能与身份证号相似。
        if(nameLength == 15 || nameLength == 18){
        	
        	String firstName = "";
        	char lastName;
        	if(nameLength == 15){
        		firstName = name.substring(0,14);
        		lastName = name.charAt(14);
        	}else{
        		firstName = name.substring(0, 17);
        		lastName = name.charAt(17);
        	}
        	
        	if(Tools.isNumeric(firstName) && Character.isLetter(lastName)){
        		return "用户名不能与身份证号相似。"; 
        	}
        }
        
        // 首字节不能是下滑线  
        String curChar_f = name.substring(0,1);
        if(curChar_f.equals("_") || curChar_f.equals("-")){
            return "用户名的首位不可以是\"_\"或\"-\"，请您重新设置。"; 
        } 
        
        // 不能包含特殊字符
        String regex1 = "^[a-zA-Z0-9_-]{1,}$"; 
        Pattern p1 = Pattern.compile(regex1);
        Matcher m1 = p1.matcher(name);
        if(m1.matches())
        {
            return "true";
        }else{
            return "用户名里不能包含特殊字符，请您重置";
        }
        
    }
    /**
     * 
     * [包装身份证号码]<BR>
     * [只显示身份证号码中的生日，其他用*代替]
     * @param mId
     * @return
     */
    public static String EncryIdNum(String mId){
        String mEncryId="";
        StringBuffer buffer = new StringBuffer();
        
        if(mId.length()==15){
            buffer.append("******");
            buffer.append(mId.substring(6, 12));
            buffer.append("***");
        }else if(mId.length()==18){
            buffer.append("******");
            buffer.append(mId.substring(6, 14));
            buffer.append("****");
        }
        mEncryId = buffer.toString();
        return mEncryId;
    }
    
    
    /**
     * 包装用户真实姓名
     * 
     * @param mTrueName 待处理的真实姓名
     * @return 处理过后的真实姓名
     */
    public static String dealTrueName(String mTrueName) {
//        姓名显示规则

//        三个字的姓名中间的用*号隐去，
//        二个字的姓名显示*客户名字，
//        三个字以上的姓名显示前后两个字，
//        中间偶数位显示，奇数位为*
        try {
            StringBuffer buffer = new StringBuffer();
            int length = mTrueName.length();
            if (length < 2) {
                throw new Exception();
            }else if(length == 2){
                buffer.append("*");
                buffer.append(mTrueName.substring(1));
            }else if(length == 3){
                buffer.append(mTrueName.substring(0, 1));
                buffer.append("*");
                buffer.append(mTrueName.substring(2, 3));
            }else if(length>3){
                buffer.append(mTrueName.substring(0, 1));
                for(int i=1;i<length-1;i++){
                    if(i%2==0){
                        buffer.append("*");
                    }else{
                        buffer.append(mTrueName.substring(i, i+1)); 
                    }                 
                }
                buffer.append(mTrueName.substring(length-1, length));
            }
            mTrueName = buffer.toString();
            return mTrueName;
        } catch (Exception e) {
            return mTrueName;
        }
    }
    
    /**
     * 
     * [验证密码强度]<BR>
     * [功能详细描述]
     * @param password 要验证的密码
     * @param uid 用户名
     * @param mobile 手机号码
     * @param birthday 出生年月日 yyyyMMdd
     * @param idcard 身份证号码    
     * @return 验证结果，true为验证通过
     */
        public static String isCorrectPW(
            String password,
            String uid,
            String mobile,
            String birthday,
            String idcard)
        {
            String value = password.trim();
            String lowPw = value.toLowerCase();
            String regex1 = "^[a-zA-Z0-9]{6,16}$"; 
            String regex2 = "^[a-zA-Z]{6,16}$"; 
            String regex3 = "^[0-9]{6,16}$";

            Pattern p1 = Pattern.compile(regex1);
            Matcher m1 = p1.matcher(value);
            Pattern p2 = Pattern.compile(regex2);
            Matcher m2 = p2.matcher(value);
            Pattern p3 = Pattern.compile(regex3);
            Matcher m3 = p3.matcher(value);
            
            if (value.length()<6 ) {
                return "密码不能少于6位，请您重新设置。";
            }
            if (value.length()>16 ) {
                return "密码不能超过16位，请您重新设置。";
            }
            if (!m1.matches()) {
                return "密码不能含有特殊符号和空格，请您重新设置。";
            }
            if (m2.matches()) {
                return "请不要设置纯字母的密码，请您重新设置。";
            }
            if(uid!=null && !uid.equals("")){
                String lowUid = uid.toLowerCase();
               
                if(lowUid.equals(lowPw)){
                    return "请不要将自己的账号作为密码，请您重新设置。";
                }
            }
            if(idcard!=null && !idcard.equals("")){
                String lowIC = idcard.toLowerCase();
                if(lowIC.equals(lowPw)){
                    return "请不要将自己的证件号作为密码，请您重新设置。";
                }
            }
            if (m3.matches()) {
                if(digitCheck(value)){
                    return "密码中不能出现连续4位及以上数字升、降序排列，请您重新设置。";
                }
                if(digitCount(value)){
                    return "密码中同一数字不能出现连续3次及以上重复，请您重新设置。";
                }
                if(CountChar(value,2,3)){
                    return "密码中不能出现连续2个数字连续3次及以上重复，请您重新设置。";
                }
                if(CountChar(value,3,2)){
                    return "密码中不能出现连续3个数字连续2次及以上重复，请您重新设置。";
                }
            }   
             if (birthday.length() == 8) {
                    String y = birthday.substring(0, 4);
                    String m = birthday.substring(4, 6);
                    String d = birthday.substring(6, 8);
                    String patten1 = y+m+d;
                    String patten2 = y+d+m;
                    String patten3 = d+m+y; 
                    if (value.contains(patten3)||value.contains(patten2)||value.contains(patten1)){
                        return "密码中不能包含出生日期，请您重新设置。"; 
                    }         
              }
            
            int moblileLength = mobile.length();
            if (moblileLength > 7) {
                String pre = mobile.substring(0,6);       
                String suf = mobile.substring(moblileLength-6,moblileLength);
                if (value.contains(pre)||value.contains(suf)) {
                    return "密码不能是电话号码前、后6位，请您重新设置。";
                }
            }

            return "true";    
        }
        /**
         * 
         * [检查密码中不能出现 dn个数字的连续rn次及以上]<BR>
         * [功能详细描述]
         * @param password
         * @param dn
         * @param rn
         * @return
         */
        private static boolean CountChar(String password,int dn, int rn){
            boolean flag = false;          
            String subString = "";
            int pLength = password.length();
            for(int loop=0;loop<dn;loop++){   
                int repeatCount = 0;
                subString = password.substring(loop,loop+dn);
                for(int i=loop;(i+dn*2)<=pLength;i++){                   
//                    String lString = password.substring(i+dn, dn*2+i);            
                    if(subString.equals(password.substring(i+dn, dn*2+i))){                     
                        repeatCount++;
                        if(repeatCount>=rn-1){
                            loop+=dn;
                            flag = true;
                            break;
                        }
                    }
                }
            }
            
            return flag;
        }
        
        /**
         * 
         * [判断数字连续不能超过3次]<BR>
         * [功能详细描述]
         * @param password
         * @return
         */
        private static boolean digitCount(String password){
            String c1,c2,c3;
            int pwLength = password.length();
            for(int i=0;(i+3)<=pwLength;i++){
                c1 =  password.substring(i, i+1);
                c2 = password.substring(i+1, i+2);
                c3 = password.substring(i+2, i+3);
                int in1 = Integer.parseInt(c1);
                int in2 = Integer.parseInt(c2);
                int in3 = Integer.parseInt(c3);
                if((0<in1&&in1<9)&&(0<in2&&in2<9)&&(0<in3&&in3<9)){
                    if((in1==in2)&&(in2==in3)){
                        return true;
                    }  
                }
                
            }
            return false;   
        }  
        /**
         * 
         * [判断升降序]<BR>
         * [功能详细描述]
         * @param password
         * @return
         */
        private static boolean digitCheck(String password){
            String c1,c2,c3,c4;
            int pwLength = password.length();
            for(int i=0;(i+4)<=pwLength;i++){
                c1 =  password.substring(i, i+1);
                c2 = password.substring(i+1, i+2);
                c3 = password.substring(i+2, i+3);
                c4 = password.substring(i+3, i+4);
                int in1 = Integer.parseInt(c1);
                int in2 = Integer.parseInt(c2);
                int in3 = Integer.parseInt(c3);
                int in4 = Integer.parseInt(c4);
                if((0<in1&&in1<9)&&(0<in2&&in2<9)&&(0<in3&&in3<9)&&(0<in4&&in4<9)){
                    if((in1==in2+1)&&(in2==in3+1)&&(in3==in4+1)||
                        (in1==in2-1)&&(in2==in3-1)&&(in3==in4-1)){
                        return true;
                    }  
                }
                
            }
            return false;   
        }
    

	/**
	 * [判断邮箱格式是否正确]<BR>
	 * [功能详细描述]
	 * @param strEmail 带验证邮箱地址
	 * @return true 正确
	 * 		   false 错误
	 * author:CUNGUANTONG465
	 * editor:CUNGUANTONG465
	 * time:2012-2-8
	 */
	public static boolean isEmail(String strEmail) {
//		String strPattern = "^[a-zA-Z][\\w\\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\\w\\.-]*[a-zA-Z0-9]\\.[a-zA-Z][a-zA-Z\\.]*[a-zA-Z]$";
		String strPattern = "[a-zA-Z0-9]{1,}[a-zA-Z0-9_-]{0,}@(([a-zA-z0-9]-*){1,}\\.){1,3}[a-zA-z\\-]{1,}";
		Pattern p = Pattern.compile(strPattern);
		Matcher m = p.matcher(strEmail.trim());
		if (m.matches()) {
			return true;
		}
		return false;
	}
	
	/**
	 * [将参数和值封装成xml节点数据]<BR>
	 * [功能详细描述]
	 * @param element
	 * @param value
	 * @return
	 */
	public static String format2Xml(String element,String value)
	{
		StringBuilder builder = new StringBuilder();
		if(!isEmpty(element)){
			value = value==null ? "" : value;
			builder.append("<"+element+">").append("<![CDATA[").append(value).append("]]>").append("</"+element+">");
		}
		return builder.toString();
	}
	
	/**
	 * [将参数和值封装成xml节点数据]<BR>
	 * [功能详细描述]
	 * @param element
	 * @param value
	 * @return
	 */
	public static String format2Xml(String element,int value)
	{
		StringBuilder builder = new StringBuilder();
		if(!isEmpty(element)){
			builder.append("<"+element+">").append("<![CDATA[").append(value).append("]]>").append("</"+element+">");
		}
		return builder.toString();
	}
	
	/**
	 * [将参数和值封装成xml节点数据]<BR>
	 * [功能详细描述]
	 * @param element
	 * @param value
	 * @return
	 */
	public static String format2Xml(String element,boolean value)
	{
		StringBuilder builder = new StringBuilder();
		if(!isEmpty(element)){
			builder.append("<"+element+">").append("<![CDATA[").append(value).append("]]>").append("</"+element+">");
		}
		return builder.toString();
	}
	
	
	/**
	 * [得到key]<BR>
	 * [功能详细描述]
	 * @param keys
	 * @return
	 */
	public static String getKey(String... keys)
	{
		if(keys == null) return "";
		StringBuffer sbKey = new StringBuffer();
		
		for(int i=0;i<keys.length;i++)
		{
			sbKey.append(keys[i]);
			if(i == keys.length -1)
			{
				break;
			}
			sbKey.append(File.separator);
		}
		return sbKey.toString();
	}
	
	/**
	 * [判断字符长度]<BR>
	 * [功能详细描述]
	 * @param str
	 * @param maxLen
	 * @return
	 */
	public static boolean isLength(String str, int maxLen) {
        char[] cs = str.toCharArray();
        int count = 0;
        int last = cs.length;
        for(int i=0; i<last; i++) {
            if(cs[i]>255) count+=2;
            else count++;
        }
        if(count >= maxLen)
        	return true;
        else
        	return false;
    }
	
	/**
	 * [获取字符串的长度，如果有中文，则每个中文字符计为2位]<BR>
	 * [功能详细描述]
	 * @param value
	 * @return
	 */
	public static int getLength(String value) {
        int valueLength = 0;
        String chinese = "[\u0391-\uFFE5]";
        for (int i = 0; i < value.length(); i++) {
            String temp = value.substring(i, i + 1);
            if (temp.matches(chinese)) {
                valueLength += 2;
            } else {
                valueLength += 1;
            }
        }
        return valueLength;
    }
	
	/**
	 * 格式化显示金额字符串
	 * "0.00"格式
	 * @param amount 要转换的金额double数字
	 * @return 格式化后的金额字符串
	 */
	public static String getAmountFormat(double amount){
		try{
		DecimalFormat df = new DecimalFormat("0.00");
		return df.format(amount);}
		catch(Exception e)
		{
			return "";
		}
	}
	
	/**
	 * @param amount
	 * @return
	 */
	public static String getStringAmountFormat(String amount){		
		try{
		double amount2 = Double.parseDouble(amount);
		DecimalFormat df = new DecimalFormat("0.00");
		return df.format(amount2);}
		catch(Exception e)
		{
			return "";
		}
	}
	
	/**
	 * @param amount
	 * @return
	 */
	public static String getStringAmountFormat1(String amount){		
		try{
			if(amount==null||amount.trim().equals("")){
				amount="0.00";
			}
			double amount2 = Double.parseDouble(amount);
			DecimalFormat df = new DecimalFormat("0.00");
			return df.format(amount2);
		}
		catch(Exception e)
		{
			return "";
		}
	}
	
	

	/** 格式化显示金额字符串
	 * "0.00"格式
	 * @param amount 要转换的金额字符串
	 * @return 格式化后的金额字符串
	 */
	public static String getAmountFormat(String amount)
	{
		try{
		Double db = Double.parseDouble(amount);
		DecimalFormat df = new DecimalFormat("0.00");
		return df.format(db);}
		catch(Exception e)
		{
			return "";
		}
	}
	/**
	 * 格式化显示金额字符串(如果输入参数转换后为空字符则返回默认0.00)
	 * "0.00"格式
	 * @param amount 要转换的金额字符串
	 * @return 格式化后的金额字符串
	 */
	public static String getAmountFormatWithEmpty(String amount)
	{
		amount = getAmountFormat(amount);
		if (amount.equals("")) {
			return "0.00";
		} else {
			return amount;
		}
	}

	/**
	 * 格式化显示净值字符串(如果输入参数转换后为空字符则返回默认0.0000)
	 * "0.0000"格式
	 * @param amount 要转换的净值字符串
	 * @return 格式化后的净值字符串
	 */
	public static String getNetvalueFormatWithEmpty(String amount)
	{
		try{
			Double db = Double.parseDouble(amount);
			DecimalFormat df = new DecimalFormat("0.0000");
			return df.format(db);}
		catch(Exception e){
			return "0.0000";
		}
	}
	
	/**
	 * 截取一段字符的长度(汉、日、韩文字符长度为2),不区分中英文,如果数字不正好，则少取一个字符位
	 * 
	 * @param str 原始字符串
	 * @param specialCharsLength
	 *            截取长度(汉、日、韩文字符长度为2)
	 * @return
	 */
	public static String trim(String str, int specialCharsLength) {
		if (str == null || "".equals(str) || specialCharsLength < 1) {
			return "";
		}
		char[] chars = str.toCharArray();
		
		int charsLength = getCharsLength(chars, specialCharsLength);
		if (charsLength < chars.length)
			return new String(chars,0,charsLength)+"...";
		return new String(chars, 0, charsLength);
	}
	/**
	 * 获取一个指定格式的String date 
	 * @param figure	相对时间上加减 相应月数
	 * @param format	格式化
	 * @param date		相对时间
	 * @return String date
	 */
	public static String getStrDataDistanceByMonth(int figure,String format,Date date){
		SimpleDateFormat asf = new SimpleDateFormat(format);
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		calendar.add(calendar.MONTH, figure);
		Date time  = calendar.getTime();
		return asf.format(time);
	}
	/**
	 * 获取加减月份前的日期
	 * @param figure	相对时间上加减 相应月数
	 * @param format	格式化
	 * @param date		相对时间
	 * @return String date
	 * @throws ParseException 非法异常
	 */
	public static String getStrDataDistanceByMonth(int figure,String format,String date) throws ParseException{
		SimpleDateFormat asf = new SimpleDateFormat(format);
		Calendar calendar = Calendar.getInstance();
		Date tempDate = asf.parse(date);
		calendar.setTime(tempDate);
		calendar.add(calendar.MONTH, figure);
		Date time  = calendar.getTime();
		return asf.format(time);
	}
	
	public static String getNatureStrDataDistance(int figure,String date,String format){
		try{
			SimpleDateFormat asf = new SimpleDateFormat(format);
			Calendar calendar = Calendar.getInstance();
			Date tempDate = asf.parse(date);
			calendar.setTime(tempDate);
			calendar.add(calendar.MONTH, figure);
			calendar.set(Calendar.DATE, 1);
			Date time  = calendar.getTime();
			return asf.format(time);
		}catch(Exception ex){
			ex.printStackTrace();
		}
		return date;
		
	}
	
	public static long getLongDataDistanceByMonth(int figure,Date date){
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		calendar.add(calendar.MONTH, figure);
		return calendar.getTimeInMillis();
	}
	
	public static Calendar getCalendarDistanceByYear(int figure,Date date){
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		calendar.add(calendar.YEAR, figure);
		return calendar;
	}
	
	/**
	 * 获取一段字符的长度，输入长度中汉、日、韩文字符长度为2，输出长度中所有字符均长度为1
	 * 
	 * @param chars 一段字符
	 * @param specialCharsLength 输入长度，汉、日、韩文字符长度为2
	 * @return 输出长度，所有字符均长度为1
	 */
	public static int getCharsLength(char[] chars, int specialCharsLength) {
		int count = 0;
		int normalCharsLength = 0;
		for (int i = 0; i < chars.length; i++) {
			int specialCharLength = getSpecialCharLength(chars[i]);
			if (count <= specialCharsLength - specialCharLength) {
				count += specialCharLength;
				normalCharsLength++;
			} else {
				break;
			}
		}
		return normalCharsLength;
	}
	
    /**
     * [计算一段字符的长度，汉、日、韩文字符长度为2，其他为1]<BR>
     * [如：中国平安PingAn，其长度是14]
     * 
     * @param chars 要计算长度的char数组
     * @return
     */
    public static int getTotalCharsLength(char[] chars)
    {
        int count = 0;
        for (int i = 0; i < chars.length; i++)
        {
            int specialCharLength = getSpecialCharLength(chars[i]);
            count += specialCharLength;
        }
        return count;
    }
    

	/**
	 * 获取字符长度：汉、日、韩文字符长度为2，ASCII码等字符长度为1
	 * 
	 * @param c 字符
	 * @return 字符长度
	 */
	private static int getSpecialCharLength(char c) {
		if (isLetter(c)) {
			return 1;
		} else {
			return 2;
		}
	}

	/**
	 * 判断一个字符是Ascill字符还是其它字符（如汉，日，韩文字符）
	 * 
	 * @param char c, 需要判断的字符
	 * @return boolean, 返回true,Ascill字符
	 */
	private static boolean isLetter(char c) {
		int k = 0x80;
		return c / k == 0 ? true : false;
	}
	
	/**
	 * 是否为空
	 * 
	 * @param value
	 * @return
	 */
	public static boolean isEmpty(String value) {
		if (value == null || value.length() == 0) {
			return true;
		}
		else
			return false;
	}

	/**
	 * 是否为数字
	 * 
	 * @param obj
	 * @return
	 */
	public static boolean isNumeric(Object obj) {
		if (obj == null) {
			return false;
		}
		String str = obj.toString();
		int sz = str.length();
		for (int i = 0; i < sz; i++) {
			if (!Character.isDigit(str.charAt(i))) {
				return false;
			}
		}
		return true;
	}
	
	/**
	 * 包装要显示的卡号信息，显示前四位后四位，中间用四位*代替
	 * 
	 * @param cardNum 待处理卡号
	 * @return 处理过后的卡号
	 */
	public static String dealTheCradNum(String cardNum) {

		try {

			StringBuffer buffer = new StringBuffer();
			buffer.append(cardNum.substring(0, 4));
			buffer.append("****");
			int length = cardNum.length();
			if (length < 8) {
				throw new Exception();
			}
			buffer.append(cardNum.substring(length - 4, length));
			cardNum = buffer.toString();
			return cardNum;
		} catch (Exception e) {
			return cardNum;
		}
	}
	/**
	 * 包装要显示的卡号信息，显示后四位，前面用四位*代替
	 * 
	 * @param cardNum 待处理卡号
	 * @return 处理过后的卡号
	 */
	public static String showAcountNum(String cardNum) {

		try {

			StringBuffer buffer = new StringBuffer();
			buffer.append("****");
			int length = cardNum.length();
			if (length < 4) {
				throw new Exception();
			}
			buffer.append(cardNum.substring(length - 4, length));
			cardNum = buffer.toString();
			return cardNum;
		} catch (Exception e) {
			return cardNum;
		}
	}
	/**
	 * 包装要显示的手机号信息，显示前三位后后位，中间用五位*代替
	 * 
	 * @param phoneNum 待处理卡号
	 * @return 处理过后的手机号
	 */
	public static String dealThePhoneNum(String phoneNum) {
		try {
			int length = phoneNum.length();
			if (length < 11) {
				throw new Exception();
			}
			StringBuffer buffer = new StringBuffer();
			buffer.append(phoneNum.substring(0, 3));
			buffer.append("*****");		
			buffer.append(phoneNum.substring(length - 3, length));
			phoneNum = buffer.toString();
			return phoneNum;
		} catch (Exception e) {
			return phoneNum;
		}
	}
	
	/**
     * 字符串按字节截取 
     * 
     * @param str 原字符 
     * @param len 截取长度
     * @return
     */
    public static String splitString(String str, int len) {  
        return splitString(str, len, "...");  
    }  
    
	 /** 
     * 字符串按字节截取 
     * 
     * @param str 原字符 
     * @param len 截取长度 
     * @param elide 省略符 
     * @return String 
     */  
     public static String splitString(String str,int len,String elide) {  
            if (str == null) return "";  
            int strlen = str.length();
            if(strlen - len > 0 ){
            	str = str.substring(0, len) + elide.trim();
            }
			return str;
     }  
     
     /**
      * 格式化利率
      * [一句话功能简述]<BR>
      * [功能详细描述]
      * @param retestRate
      * @return
      */
     public static String formatReterestRate(String strRetestRate) {
         double retestRate ;
         try {
             retestRate = Double.parseDouble(strRetestRate);
         } catch (Exception e) {
             return "0.00%";
         }
//         retestRate *= 10;
         DecimalFormat df = new DecimalFormat("0.00");
         return df.format(retestRate) + "%";
     }
	
	/**
	 * 判断是否为0，价格显示时，为零则要显示
	 * @param str
	 * @return
	 */
	public static boolean isStringZero(String str) {
		if (str == null)
			return false;
		String s = str.replace(".", "");
		try {
			int num = Integer.valueOf(s);
			if (num == 0)
				return true;
			else
				return false;
		} catch (Exception e) {
			return false;
		}

	}

	/**
	 * 改变背景的透明度
	 * @param v
	 */
	public static void changeBackgroundAlpha(View v) {
		Drawable mDrawable1 = v.getBackground();
		mDrawable1.setAlpha(200);
		v.invalidate();
		mDrawable1.setAlpha(255);
		v.invalidate();
		
	}
	
	
	/***************************有关字符串处理方法**************************/
	
	/**
	 * 去除String字符串中指定字符
	 * @param str<br>需去除指定字符的字符串
	 * @param s<br>指定去除的字符
	 * @return<br> 处理后的字符串
	 * 注：已测试通过
	 */
	public static String split(String str,String s){
		StringBuffer sb = new StringBuffer();
		String[] str2 = str.split(s);
		for(int i=0;i<str2.length;i++)
			sb.append(str2[i]);
		return sb.toString();
	}
	
	/**
	 * 将日期类型转换为Date类型
	 * @param dateString
	 * @return
	 */
	public static String dateStringToDate(String dateString){
	    if (isEmpty(dateString)) {
	        return "";
	    }
	    if (dateString.length() < 8 ) {
	        return "";
	    } else if(dateString.length() > 8) {
	    	return dateString;
	    }
	    
		StringBuffer sb = new StringBuffer();
		sb.append(dateString);
		sb.insert(4, "-");
		sb.insert(7, "-");
		return sb.toString();
	}
	
	/**
	 * @param dateString
	 * @return
	 */
	public static String yMStringToDate(String dateString){
		StringBuffer sb = new StringBuffer();
		sb.append(dateString);
		sb.insert(4, "-");
		return sb.toString();
	}
	
	/**
	 * 对形如2010-10-10格式的日期转换成20101010
	 * @param date
	 * @return
	 */
	public static String dateToDateString(String date) {
	    if (isEmpty(date)) {
	        return null;
	    }
        String date2 = date.replaceAll("-", "");
	    return date2;
	}
	
	public static boolean isNumberDecimal(String decimal){
		try {
			Float.parseFloat(decimal);
		} catch (Exception e) {
			// TODO: handle exception
			return false;
		}
		return true;
		
	}
	
	
	/***************************有关日期/时间处理方法*************************/
	/**
	 * 把日期从旧到新排序。
	 * @param monthList<br>月份列表或日期列表
	 * 列表元素格式如：20110102（日期）、201108（年月）
	 * @return int[]<br> 
	 */
	public static int[] sortMonth(String[] monthList){
		if(monthList!=null){
			int len = monthList.length;
			int[] temp = new int[len];
			int t = 0;
			for(int i=0;i<len;i++){
				temp[i] = Integer.parseInt(monthList[i]);
			}
			for(int i=0;i<len;i++){
				for(int j=i+1;j<len;j++){
					if(temp[i]>temp[j]){
						t = temp[i];
						temp[i] = temp[j];
						temp[j] = t;
					}
				}
			}
			return temp;
		}else
			return null;
	}
	
	/**
	 * 获取当前年月，格式如：201101
	 * @return String<br>
	 */
	public static String getCurrentYM(){
		Calendar c = Calendar.getInstance();
		int y = c.get(Calendar.YEAR);
		int m = c.get(Calendar.MONTH);
		if(0==m){
			m = 12;
		}
		if(0<m && m<10){
			String m2 = "0"+String.valueOf(m);
			return String.valueOf(y) + m2;
		}else{
			return String.valueOf(y)+String.valueOf(m);
		}
	}
	
	public static String LongToFormatDate(Long time,String format){
		SimpleDateFormat sdf = new SimpleDateFormat(format);
		String date = sdf.format(new Date(time));
		return date;
	}
	
	public static String DateToFormatDate(Date time,String format){
		SimpleDateFormat sdf = new SimpleDateFormat(format);
		String date = sdf.format(time);
		return date;
	}
	
	public static Calendar dateToCalendar(Date time){
		
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
		String dateStr = dateFormat.format(time);
		String year = dateStr.substring(0, 4);
		String month = dateStr.substring(4, 6);
		String day = dateStr.substring(6);
		    
		Calendar currentTime = Calendar.getInstance();
		    
		currentTime.clear();
		currentTime.set(Calendar.YEAR, Integer.parseInt(year));
		currentTime.set(Calendar.MONTH, Integer.parseInt(month) - 1);
		currentTime.set(Calendar.DAY_OF_MONTH, Integer.parseInt(day));
		return currentTime;
	}
	
	public static Date StringToDate(String date,String formart) throws ParseException{
		SimpleDateFormat sdf = new SimpleDateFormat(formart);
		return sdf.parse(date);
	}
	
	public static String StringToDate(String date,String fromFormart,String toFormart) {
		if(date!=null&&fromFormart!=null&&toFormart!=null){
			try {
				SimpleDateFormat fromSDF = new SimpleDateFormat(fromFormart);
				SimpleDateFormat sdf = new SimpleDateFormat(toFormart);
				Date tempDate = fromSDF.parse(date);
				return sdf.format(tempDate);
			} catch (ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		return date;
	}
	
	public static long convert2long(String date , String format)
	{
		try {
			if(!Tools.isEmpty(date)){
				SimpleDateFormat sdf = new SimpleDateFormat(format);
				return sdf.parse(date).getTime();
			}
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return 0L;
	}
	
	public static String format(Date date, String format) {
	    SimpleDateFormat sdf = new SimpleDateFormat(format);
	    return sdf.format(date);
	}
	
	public static Date format(String dateStr, String format) {
		try {
			Date date = new SimpleDateFormat(format).parse(dateStr);
			return date;
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	public static String format(Calendar calendar, String format) {
	    return format(calendar.getTime(), format);
	}
	
	   
    public static Calendar strToCalendar(String dateStr, String format) {
        SimpleDateFormat fromSDF = new SimpleDateFormat(format);
        Date dateBeginDate = null;
        try
        {
            dateBeginDate = fromSDF.parse(dateStr);
        }
        catch (ParseException e)
        {
            return null;
        }
        
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(dateBeginDate);
        return calendar;
    }
    
    /**
     * 格式把Calendar对象格式化化成 yyyy年MM月dd日,星期X"的样式
     * @param calendar
     * @return
     */
    public static String formatDateWithWeek(Calendar calendar) {
        
        return formatDateWithWeek(calendar, "yyyy年MM月dd日, 星期");
    }
    
    public static String formatDateWithWeek(Calendar calendar, String format) {
        String formatStr = Tools.format(calendar, format);
        int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
        APPLog.i("Tools", "dayOfWeek:" + dayOfWeek);
        String week = null;
        switch (dayOfWeek) {
            case Calendar.SUNDAY:
                week = "日";
                break;
            case Calendar.MONDAY:
                week = "一";
                break;
            case Calendar.TUESDAY:
                week = "二";
                break;
            case Calendar.WEDNESDAY:
                week = "三";
                break;
            case Calendar.THURSDAY:
                week = "四";
                break; 
            case Calendar.FRIDAY:
                week = "五 ";
                break;
            case Calendar.SATURDAY:
                week = "六";
                break;
        }
        formatStr = formatStr + week;
        return formatStr;
    }
    
	
	/***************************************************************************/
	
	/**
	 * 列表倒序
	 * @param list
	 * @return
	 */
	public static List<Map<String,Object>> reverse(List<Map<String,Object>> list){
		List<Map<String,Object>> l = new ArrayList<Map<String,Object>>();
		int size = list.size();
		for(int i=size;i>0;i--){
			l.add(list.get(i));
		}
		return l;
	}
	/**
	 * 计算总记录页数
	 * @param count 总记录数
	 * @param pageSize 每页记录数
	 * @return
	 */
	public static int getTotalPageCount(String count,String pageSize){
		int c = Integer.valueOf(count).intValue();	
		int ps = Integer.valueOf(pageSize).intValue();
		if(0==c){   //总记录数为0
			return 0;
		}
		if(c<=ps){	//总记录数小于一页
			return 1;
		}else{	    //总记录数不为每页记录数的整数倍
			int n = c/ps;
			if(c%ps!=0){
				n++;
			}
			return n;
		}
	}
	
	
	
	/**
	 * [一句话功能简述]<BR>
	 * [功能详细描述]
	 * @param executePeriod 0：每天;1：每周;2：每月
	 * @param executeDate 
	 * 执行周期为每天：0
	 * 执行周期为每周：1、2、3、4、5、6、0(周日)
	 * 执行周期为每月：1到28、32（月末）
	 * @param executeTime 00：上午 01：下午
	 * @return
	 */
	public static String getExecuteTime(String executePeriod, String executeDate, String executeTime)
	{
		StringBuilder timeinfo = new StringBuilder();
		
		if(!Tools.isEmpty(executePeriod))
		{
			if("0".equals(executePeriod))
				timeinfo.append("每天");
			if("1".equals(executePeriod))
				timeinfo.append("每周");
			if("2".equals(executePeriod))
				timeinfo.append("每月");
		}
		
		timeinfo.append(" ");
		
		if(!Tools.isEmpty(executeDate))
		{
			if("1".equals(executePeriod))
			{
				if("0".equals(executeDate))
					timeinfo.append("星期天");
				if("1".equals(executeDate))
					timeinfo.append("星期一");
				if("2".equals(executeDate))
					timeinfo.append("星期二");
				if("3".equals(executeDate))
					timeinfo.append("星期三");
				if("4".equals(executeDate))
					timeinfo.append("星期四");
				if("5".equals(executeDate))
					timeinfo.append("星期五");
				if("6".equals(executeDate))
					timeinfo.append("星期六");
			}
			if("2".equals(executePeriod))
			{
				timeinfo.append(executeDate);
			}
		}
		
		timeinfo.append(" ");
		
		if(!Tools.isEmpty(executeTime))
		{
			if("00".equals(executeTime))
				timeinfo.append("上午");
			if("01".equals(executeTime))
				timeinfo.append("下午");
		}

		return timeinfo.toString();
	}
	
	/**
	 * [一句话功能简述]<BR>
	 * [功能详细描述]
	 * @param executePeriod 执行周期为单次：日期（年月日），日期格式：yyyy-MM-dd 
	 * @param executeTime 00：上午 01：下午
	 * @return
	 */
	public static String getExecuteTime(String executeDate, String executeTime)
	{
		StringBuilder timeinfo = new StringBuilder();
		
		if(!Tools.isEmpty(executeDate))    
		{
			Date date = Tools.format(executeDate, "yyyy-MM-dd");
			timeinfo.append(Tools.format(date, "yyyy年  MM月  dd日"));
		}
		
		timeinfo.append(" ");
		
		if(!Tools.isEmpty(executeTime))
		{
			if("00".equals(executeTime))
				timeinfo.append("上午");
			if("01".equals(executeTime))
				timeinfo.append("下午");
		}

		return timeinfo.toString();
	}
	
	/**
	 * [一句话功能简述]<BR>
	 * [功能详细描述]
	 * @param executeType 1:预约、2:周期、3：当天实时、4：普通、5：加急
	 * @return
	 */
	public static String getExecuteTime(String executeType)
	{
		if("1".equals(executeType)){
			return "预约转账";
		}
		if("2".equals(executeType)){
			return "周期转账";
		}
		if("3".equals(executeType)){
			return "实时";
		}
		if("4".equals(executeType)){
			return "普通";
		}
		if("5".equals(executeType)){
			return "加急";
		}
		return "实时";
	}
	
    /**
     * 在日期前加一个0
     * 如　1 返回 "01"
     *  10 返回　"10"
     * [一句话功能简述]<BR>
     * [功能详细描述]
     * @param day
     * @return
     */
    public static String formatDay(int day) {
        if (day < 10) {
            return "0" + day;
        }
       return String.valueOf(day); 
    }
    
    /**
     * 从字符串日期中滤出年月日
     * 如2011-11-11
     * Calander.YEAR 得 2011
     * Calander.MONTH 得11
     * Calander.DAY_OF_MONTH 得11
     * [一句话功能简述]<BR>
     * [功能详细描述]
     * @param field
     * @param dateString
     * @return
     */
    public static int getDateFieldFormStringDate(int field, String dateString) {
        if (isEmpty(dateString)) {
            throw new RuntimeException("Empty dateString");
        }
        if (dateString.length() < 10 ) {
            throw new RuntimeException("dateString length error");
        }
        
        String[] dates = dateString.split("-");
        
        switch (field) {
            case Calendar.YEAR:
                return Integer.parseInt(dates[0]);
            case Calendar.MONTH:
                return Integer.parseInt(dates[1]);
            case Calendar.DAY_OF_MONTH:
                return Integer.parseInt(dates[2]);
        }
        return -1;
    }

    /**
     * 从字符串日期中滤出年月
     * 如2011-11
     * Calander.YEAR 得 2011
     * Calander.MONTH 得11
     * @param field
     * @param dateString
     * @return
     */
    public static int getDateFieldFormStringYearAndMonth(int field, String dateString) {
        if (isEmpty(dateString)) {
            throw new RuntimeException("Empty dateString");
        }
        if (dateString.length() < 7 ) {
            throw new RuntimeException("dateString length error");
        }
        
        String[] dates = dateString.split("-");
        
        switch (field) {
            case Calendar.YEAR:
                return Integer.parseInt(dates[0]);
            case Calendar.MONTH:
                return Integer.parseInt(dates[1]);
        }
        return -1;
    }
    
    /**
     * 获取根据屏幕获取实际大小
     * 在自定义控件中，根据屏幕的大小来获取实际的大小
     * 
     * @param ctx
     * @param orgSize
     * @return
     */
    public static int getActualSize(Context ctx, int orgSize) {
        WindowManager windowManager = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE);
        
        DisplayMetrics displayMetrics = new DisplayMetrics();
        windowManager.getDefaultDisplay().getMetrics(displayMetrics);
        float density = (float) displayMetrics.density;
        
        return (int)(orgSize * density);
    }
    /**
	 * [一句话功能简述]<BR>
	 * [功能详细描述]
	 * @param executeType 0:对公客户、1:借记卡、2：个人存折、3：贷记卡
	 * @return
	 */
	public static String getAcountType(String acountType)
	{
		if("0".equals(acountType)){
			return "对公客户";
		}
		if("1".equals(acountType)){
			return "借记卡";
		}
		if("2".equals(acountType)){
			return "个人存折";
		}
		if("3".equals(acountType)){
			return "贷记卡";
		}
		return  "";
	}
	
	public static String getRegisterType(String type) {
		if (type != null && ! type.equals("")) {
			if (type.equals("0")) {
				return "转入活期账户";
			} else if (type.equals("1")) {
				return "本息续存为1天通知存款";
			} else if (type.equals("7")) {
				return "本息续存为7天通知存款";
			} else {
				return "服务器数据返回有误";
			}
		} 
		return "未知";
	}
	
	public static String getCancelType(String isCancel) {
		if (isCancel != null && ! isCancel.equals("")) {
			if (isCancel.equals("3")) {
				return "已撤销";
			} else {
				return "未撤销";
			}
		}
		return "";
	}
	/**
	 * 根据currCode返回对应的中文名称
	 * 如：0123，对应的就是：人民币,欧元
	 * @param currCode
	 * @return
	 */
	public static String getCurrType(String currCode){
		String currType = "";
		String tempStr = "";
		int currLen = 0;
		if(currCode != null && currCode.length()>0){
			int currCodeLen = currCode.length();
			while(currLen <currCodeLen){
				tempStr = currCode.substring(currLen, currLen+2);
				if(tempStr.equals("01")){
					currType += "人民币,";
				}else if(tempStr.equals("23")){
					currType += "欧元,";
				}else if(tempStr.equals("28")){
					currType += "加拿大元,";
				}else if(tempStr.equals("13")){
					currType += "港币,";
				}else if(tempStr.equals("27")){
					currType += "日元,";
				}else if(tempStr.equals("15")){
					currType += "瑞士法郎,";
				}else if(tempStr.equals("14")){
					currType += "美元,";
				}else if(tempStr.equals("18")){
					currType += "新加坡元,";
				}else if(tempStr.equals("29")){
					currType += "澳大利亚元,";
				}else if(tempStr.equals("12")){
					currType += "英镑,";
				}
				currLen += 2;
			}
			currType = currType.substring(0, currType.length()-1);
			Log.e("currType", currType);
		}
		return currType;
	}
	/**
	 * 根据currCode返回对应的中文名称
	 * 如：0123，对应的就是：人民币,欧元
	 * @param currType
	 * @return
	 */
	public static String getCurrCode(String currType){
		String currCode = "";
		String tempStr = "";
		int i;
		if(currType != null && currType.length()>0){
			String[] tempArray = currType.split(",");
			int currCodeLen = tempArray.length;
			for(i = 0 ; i < currCodeLen; i++ ){	
				tempStr = tempArray[i];
				if(tempStr.equals("人民币")){
					currCode += "01";
				}else if(tempStr.equals("欧元")){
					currCode += "23";
				}else if(tempStr.equals("加拿大元")){
					currCode += "28";
				}else if(tempStr.equals("港币")){
					currCode += "13";
				}else if(tempStr.equals("日元")){
					currCode += "27";
				}else if(tempStr.equals("瑞士法郎")){
					currCode += "15";
				}else if(tempStr.equals("美元")){
					currCode += "14";
				}else if(tempStr.equals("新加坡元")){
					currCode += "18";
				}else if(tempStr.equals("澳大利亚元")){
					currCode += "29";
				}else if(tempStr.equals("英镑")){
					currCode += "12";
				}
			}
			Log.e("currCode", currCode);
		}
		return currCode;
	}
	/**
	 * 把list的String用“,”拼接起来
	 * 如list有“我”、“是”、“超”、“人”，拼接后是：“我,是,超,人”
	 * @param list 拼接前的list
	 * @return nectString 拼接后的字符串
	 */
	public static String connectStringByComma(List<String> list){
		String nectString = "";
		if(list != null && list.size()>0){
			int i;
			int len = list.size();
			for(i=0; i<len; i++){
				nectString = nectString + list.get(i) + ",";
			}
			nectString = nectString.substring(0, nectString.length()-1);
		}
		return nectString;
	}
	public static String getPurchaseModel(String purchaseModel) {
		if("0".equals(purchaseModel)){
			return "按投资期数";
		}
		if("1".equals(purchaseModel)){
			return "按结束日期";
		}
		if("2".equals(purchaseModel)){
			return "按成功期数";
		}
		
		return  "";
	}
	
	public static String getPaymentCity(String cityCode) {
		if (cityCode != null) {
			if (cityCode.equals("0")) {
				return "深圳";
			} else if (cityCode.equals("1")) {
				return "上海";
			} else if (cityCode.equals("2")) {
				return "福州";
			} else if (cityCode.equals("3")) {
				return "泉州";
			} else if (cityCode.equals("9")) {
				return "全国";
			}
		}
		return "";
	}
	
	/**
	 * 获取地球上，两个经纬度点的距离
	 */
    private final static double EARTH_RADIUS = 6378.137;  
    public static double gps2m(double lat_a, double lng_a, double lat_b, double lng_b) {
       double radLat1 = (lat_a * Math.PI / 180.000);
       double radLat2 = (lat_b * Math.PI / 180.000);
       double a = radLat1 - radLat2;
       double b = (lng_a - lng_b) * Math.PI / 180.000;
       double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2)
              + Math.cos(radLat1) * Math.cos(radLat2)
              * Math.pow(Math.sin(b / 2), 2)));
       s = s * EARTH_RADIUS;
       s = Math.floor(s * 1000+0.5) / 1000;
       return s;
    }
	
	public static String joinAliasAndAccNum(Object alias,Object accNum){
		if(accNum!=null){
			String aliasStr = "未命名";
			String accNumStr = accNum.toString();
			if(alias!=null){
				aliasStr = alias.toString();
			}
			if(aliasStr.length()>5){
				aliasStr = aliasStr.substring(0,3)+"..： ";
			}else{
				aliasStr+="： ";
			}
			accNumStr = aliasStr+dealTheCradNum(accNumStr);
			return accNumStr;
		}
		return "";
	}
	
	public static int indexOfListMap(List<Map<String, String>> list, Object obj, String key) {
		
		int listSize = list.size();
		for (int i = 0;i < listSize;i++) {
			Map<String, String> map = list.get(i);
			Object value = map.get(key);
			if (obj.equals(value)) {
				return i;
			}
		}
		return -1;
	}
	
	public static String getNetPayTranState(String strState) {
	    int state = -1;
	    try {
	        state = Integer.parseInt(strState);
	    } catch (Exception e) {
	        return "";
	    }
	    switch (state) {
	        case 3:
	            return "支付成功";
	        case 9:
	            return "清算成功";
	        case 10:
	            return "支付成功";
	    }

	    return "";
	}
	
	/**
	 * 获取屏幕的深度值
	 * [一句话功能简述]<BR>
	 * [功能详细描述]
	 * @param ctx
	 * @return
	 */
	public static float getScreenDensity(Context ctx) {
	    WindowManager mWindowManager = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE);
	    DisplayMetrics displayMetrics = new DisplayMetrics();
	    mWindowManager.getDefaultDisplay().getMetrics(displayMetrics);
	    float density = displayMetrics.density;
	    return density;
	}
	
	/**
	 * 获取账户状态的显示值
	 * @param state
	 * @return
	 */
	public static final String getAccStatus(int state) {
	    switch (state) {
	        case 41:
	            return "正常";
	        case 42:
	            return "法院冻结";
	        case 43:
	            return "止付";
	        case 44:
	            return "等待身份认证（卡与账户未激活）";
	        case 45:
	            return "不动户";
	        case 46:
	            return "转收益";
	        case 47:
	            return "等待身份认证（卡激活，账户未激活）";
	        case 48:
	            return "待取消账户";
	        case 49:
	            return "欠息账户";
	        case 50:
	            return "第三方托管账户";
	        case 51:
	            return "信贷资金监管账户（对公）";
	        case 52:
	            return "信贷资金监管账户（零售）";
	        case 53:
	            return "理财账户";
	        case 54:
	            return "基金账户";
	        case 55:
	            return "还款账户";
	        case 56:
	            return "纳税人账户";
	        case 57:
	            return "注册公司账户";
	        case 58:
	            return "免税账户";
	        case 59:
	            return "抵押账户";
	        case 60:
	            return "联名存款帐户";
	        case 61:
	            return "验资账户";
	    }
	    return "";
	}
	/**
	 * 
	 * [获取小数的整数部分]<BR>
	 * [功能详细描述]
	 * @param doubleStr 小数字符串
	 * @return
	 * 	   整数部分
	 */
	public static String getIntegerFromDouble(String doubleStr){
		if(doubleStr != null && doubleStr != ""){
			return doubleStr.substring(0, doubleStr.indexOf("."));
		}
		return "";
	}
	
	public static String getStrFromMap(Map<String, Object> map,String key){
		Object ob = map.get(key);
		if(ob!=null){
			return ob.toString();
		}
		return "";
	}
	
	   /**
     * [判断邮箱格式是否正确]<BR>
     * [功能详细描述]
     * @param strEmail 带验证邮箱地址
     * @return true 正确
     *         false 错误
     * author:CUNGUANTONG465
     * editor:CUNGUANTONG465
     * time:2012-2-8
     */
    public static boolean isMobilePhoneNumber(String phoneNumber) {
        
        // 移动手机号码
        String mPattern = "(^134[0-8]\\d{7}$)|(^13[5-9]\\d{8}$)|(^15[01789]\\d{8}$)|(^18[78]\\d{8}$)|(^1349\\d{7}$)";
        
        // 联通号码
        String uniPattern= "(^1349\\d{7}$)|(^13[12]\\d{8}$)|(^156\\d{8}$)|(^18[6]\\d{8}$)";
        
        //电信号码验证正则表达式
        String ePattern= "(^1[35]3\\d{8}$)|(^189\\d{8}$)";
        
        Pattern pm = Pattern.compile(mPattern);
        Matcher mm = pm.matcher(phoneNumber.trim());
        
        Pattern um = Pattern.compile(uniPattern);
        Matcher mu = um.matcher(phoneNumber.trim());
        
        Pattern em = Pattern.compile(ePattern);
        Matcher me = em.matcher(phoneNumber.trim());
        
        if (mm.matches() || mu.matches() || me.matches()) {
            return true;
        }
        
        return false;
    }
}
